package cn.com.zhuxulin.info.Forms;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;

import cn.com.zhuxulin.info.Services.IPInfo;

public class IP extends Form {
//	private Display display=null;
	private TextField ip=null;
	private TextField ipInfo=null;
	private Command ok=null;
	private Command back=null;
	//private Form form=null;
	public IP(final Display display,final Start start){
		super("IPInfo Powered By ZhuXulin");
//		this.display=display;
		//display=Display.getDisplay(this);
		ip=new TextField("IP:", "180.141.127.216", 15, TextField.ANY);
		ipInfo=new TextField("IP:", "No data", 100, TextField.ANY);
		ok=new Command("OK", Command.SCREEN, 1);
		back=new Command("Back", Command.BACK, 1);
		//form=new Form("IPInfo Powered By ZhuXulin");
		this.append(ip);
		this.append(ipInfo);
		this.addCommand(ok);
		this.addCommand(back);
		//display.setCurrent(form);
		this.setCommandListener(new CommandListener() {
			public void commandAction(Command cmd, Displayable arg) {
				if(cmd==ok){
					new Thread(new Runnable() {
						public void run() {
							IPInfo info=new IPInfo();
							info.setIP(ip.getString());
							String result="";
							String[] tmp=info.getIPInfo();
							for(int i=0;i<tmp.length;i++){
								result+=tmp[i]+"\n";
								//System.out.println("result:"+result);
							}
							ipInfo.setString(result);
						}
					}).start();
				}
				if(cmd==back){
					display.setCurrent(start);
				}
			}
		});
	}
}
